import SceneRoaming from "../ScreenRoaming";
import CreatePolyline from "../../Draw/BrokenLine/CreatePolyline";
const Cesium = window.Cesium;
export default class Path {
  _viewer: any;
  PathRoamingLine: any;
  sceneRoaming: any;
  handler: any;
  constructor(viewer:any) {
    this._viewer = viewer;
  }
  start(speed:any, height:any) {
    let viewer = this._viewer;
    const callback = (e:any) => {
      this.PathRoamingLine = e;
      this.sceneRoaming = new SceneRoaming(
        viewer,
        e.PottingPoint,
        speed,
        height
      );

      this.sceneRoaming.startRoaming(true, {
        height: height,
        afterCallback: (tick:any) => {
          console.log("o hou", tick);
          //清空临时点
          alert("漫游结束！");
          viewer.entities.remove(e);

          // globalMarkers.forEach(marker => viewer.entities.remove(marker));
        },
      });
    };
    this.createPolygonLine(viewer, {}, callback);
  }
  stop() {
    this.sceneRoaming.pauseRoaming();
  }
  continue() {
    this.sceneRoaming.continueRoaming();
  }
  changeOption(e:any){
    this.sceneRoaming.change(e)
  }
  destroy() {
    this.sceneRoaming.destroyRoaming();
    this._viewer.entities.remove(this.PathRoamingLine);
  }
  createPolygonLine(viewer:any, option:any, callbackForInfo:any) {
    if (this.handler) this.handler.destroy();
    this.handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    const resultList:any = [];
    const callback = (event:any) => {
      console.log(event, "event");
      if (callbackForInfo && typeof callbackForInfo == "function")
        callbackForInfo(event);
    };
    CreatePolyline(viewer, this.handler, resultList, option, callback);
  }
}
